
import CryptoJS from "crypto-js";

//key的字符串要超過16個，iv要超過6個。否則解密出來為空
export const SECRET_KEY = CryptoJS.enc.Utf8.parse("compeq12345678900123");
export const SECRET_IV = CryptoJS.enc.Utf8.parse("99999999123");

export const encrypt = (password: string) => {
  const turePwdEncrypt = CryptoJS.AES.encrypt(password, SECRET_KEY, {
    iv: SECRET_IV,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  return turePwdEncrypt.toString();
};

export const decrypt = (username: string) =>{
  const turePwddecrypt = CryptoJS.AES.decrypt(username, SECRET_KEY, {
    iv: SECRET_IV,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  });
  return CryptoJS.enc.Utf8.stringify(turePwddecrypt)
}